package com.lagou.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitConfig {

    @Bean
    public Queue queue() {
        Map<String, Object> props = new HashMap<>();
        props.put("x-message-ttl", 10000);
        // 关联死信交换器ex.go.dlx
        props.put("x-dead-letter-exchange", "ex.payment.dlx");
        // 死信队列使用的routingkey
        props.put("x-dead-letter-routing-key", "key.payment.dlx");

        return new Queue("payment", false, false, false, props);
    }

    @Bean
    public Queue queueDlx() {
        Map<String, Object> props = new HashMap<>();

        return new Queue("payment.dlx", false, false, false, props);
    }

    @Bean
    public Exchange exchange() {
        return new DirectExchange("ex.payment", false, false, null);
    }

    @Bean
    public Exchange exchangeDlx() {
        return new DirectExchange("ex.payment.dlx", false, false, null);
    }

    @Bean
    public Binding binding() {
        return new Binding("payment", Binding.DestinationType.QUEUE, "ex.payment", "key.payment",
                null);

    }

    @Bean
    public Binding bindingDlx() {
        return new Binding("payment.dlx", Binding.DestinationType.QUEUE, "ex.payment.dlx", "key.payment.dlx",
                null);

    }

}
